<template>
  <div class="photoList">
    <van-tabs animate>
      <van-tab
        v-for="item in cates"
        :key="item.id"
      >
        <template #title>
          <div @click="getImages(item.id)">
            {{ item.title }}
          </div>
        </template>
      </van-tab>
    </van-tabs>
    <div
      class="img-box"
      v-if="images.length > 0"
    >
      <img
        v-for="item in images"
        :key="item.id"
        v-lazy="item.img_url"
        alt=""
        @click="goDetail(item.id)"
      />
    </div>
    <div v-else>暂无数据</div>
  </div>
</template>
<script>
import { getimgcategory, getImages } from "@/api";
export default {
  data() {
    return {
      cates: [],
      images: [],
    };
  },
  created() {
    this.getimgcategory();
    this.getImages(0);
  },
  methods: {
    async getimgcategory() {
      const res = await getimgcategory();
      res.data.message.unshift({
        id: 0,
        title: "全部",
      });
      this.cates = res.data.message;
    },
    async getImages(id) {
      const res = await getImages(id);
      this.images = res.data.message;
    },
    goDetail(id) {
      this.$router.push("/home/photoinfo/" + id);
    },
  },
};
</script>
<style lang="scss">
.photoList {
  .van-tab--active {
    font-weight: 700;
  }
  .img-box {
    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
